package com.oocl.euc.core.builder;

import com.oocl.euc.core.maintenance.model.Role;
import com.oocl.euc.core.maintenance.model.RoleAuth;
import com.oocl.euc.core.maintenance.repository.RoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Set;

@Component
public class RoleBuilder {

    private Role role;
    @Autowired private RoleRepository roleRepository;

    public RoleBuilder defaultBuilder() {
        this.role = new Role();
        this.role.setRoleName("Test Role Name");
        this.role.setRoleDesc("Test Role Desc");
        return this;
    }

    public RoleBuilder withRoleName(String roleName) {
        role.setRoleName(roleName);
        return this;
    }

    public RoleBuilder withRoleDesc(String roleDesc) {
        role.setRoleDesc(roleDesc);
        return this;
    }

    public RoleBuilder withRoleAuths(Set<RoleAuth> roleAuths) {
        role.setRoleAuths(roleAuths);
        return this;
    }

    public Role create() {
        return role;
    }

    public Role saveToDB() {
        roleRepository.save(role);
        return role;
    }
}
